//
//  JSUtils.m
//  demo
//
//  Created by RYAN on 15/8/11.
//
//

#import "JSHelper.h"

@implementation JSHelper

+ (NSString *)removeWebView:(NSString *)identifier{
    return [NSString stringWithFormat:@"bsl.webview.removeView(\"%@\")",identifier];
}

+ (NSString *)updateWebViewUrl:(NSString *)identifier url:(NSString *)newUrl{
    return [NSString stringWithFormat:@"bsl.webview.updateUrls(\"%@\",\"%@\",\"loaded\")",identifier,newUrl];
}

+ (NSString *)triggerEvent:(NSString *)identifier type:(NSString *)eventType{
    return [NSString stringWithFormat:@"bsl.webview.triggerEventOfType(\"%@\",\"%@\")",identifier,eventType];
}

+ (NSString *)clearLocalStorage{
    return [NSString stringWithFormat:@"window.localStorage.removeItem(\"tempObj\");window.localStorage.removeItem(\"allWebViews\");%@;",[JSHelper updateCurrentWebviewId:@"LaunchWebViewID"]];
    
//    return @"window.localStorage.removeItem(\"tempObj\");window.localStorage.removeItem(\"allWebViews\");window.localStorage.removeItem(\"currentWebView\");";
}

+ (NSString *)updateCurrentWebviewId:(NSString *)Id{
    return [NSString stringWithFormat:@"window.localStorage.setItem(\"currentWebView\",\"%@\")",Id];
}

+ (NSString *)refreshCallback:(NSString *)Id{
    return [NSString stringWithFormat:@"window.onRefresh[\'%@\']();",Id];
}
@end
